#include <bits/stdc++.h>

using namespace std;

int n, sk = 0, id[1005];
string op, ad, se[1005]; 

int s_to_num(string s)
{
	int t, a = 0;
	for(int i = 0;i < s.size();i++)
	{
		t = s[i] - '0';
		a = a * 10 + t;	
	}
	return a;
}

bool check(string a)
{
	string t;
	int la = 0;
	for(int i = 0;i < a.size();i++)
	{
		if(!(a[i] >= '0' && a[i] <= '9')) t += a[i];
	}
	if(t != "...:") return false;
	for(int i = 0;i < a.size();i++)
	{
		if(a[i] == '.' || a[i] == ':')
		{
			t = a.substr(la, i - la);
			if(t.size() > 1 && t[0] == '0') return false;
			if(s_to_num(t) > 255) return false;
			la = i + 1;
		}
		if(a[i] == ':')
		{
			t = a.substr(i + 1, a.size());
			if(t.size() > 1 && t[0] == '0') return false;
			if(s_to_num(t) > 65535) return false;
		}
	}
	return true;
}

int main()
{
	freopen("network.in", "r", stdin);
	freopen("network.out", "w", stdout);
	cin >> n;
	for(int x = 1;x <= n;x++)
	{
		cin >> op >> ad;
		if(!check(ad)) cout << "ERR\n";
		else 
		{
			if(op == "Server")	
			{
				bool same = false;
				for(int i = 1;i <= sk;i++)
				{
					if(se[i] == ad)
					{
						same = true;
						break;
					}
				}
				if(!same)
				{
					se[++sk] = ad;
					id[sk] = x;
					cout << "OK\n";
				}
				else
				{
					cout << "FAIL\n";
				}
			}
			else
			{
				bool su = false;
				for(int i = 1;i <= sk;i++)
				{
					if(se[i] == ad)
					{
						su = true;
						cout << id[i] << endl;
						break;
					}
				}
				if(!su) cout << "FAIL\n";
			}
		}	
	}	
	return 0;
}
